<script setup>
defineProps({
  msg: {
    type: String,
    required: true
  }
})

import { computed, reactive, ref, shallowReactive, watch } from 'vue';


const myData = reactive([1, 2, 3])
const myData2 = reactive(
// const myData2 = shallowReactive(
  {
    name: 'wuyou',
    age: 18,
    friends: ['李蕾', '汉妹妹']
  }
)
const count = ref(0)
const content = ref('这是一段测试内容')
const getLen = computed(() => { 
  console.log('计算了执行')
  return content.value.length
})

const arr = ['a', 'b', 'c', 'd']
const obj = {
  'a': 1,
  'b': 2,
  'c': 3,
  'd': 4,
}

function clickHandler() { 
  myData.push(10)
  myData2.friends.push('小小')
  count.value++
  content.value += '!'
}
function now() {
  return Date.now()
}
watch(count, (newValue, oldValue) => { 
  console.log(newValue, oldValue)
})

</script>

<template>
  <div class="greetings">
    <h1 class="green">{{ msg }}</h1>

    <h3 class="green">{{ myData }}</h3>
    <h3 class="green">{{ myData2 }}</h3>
    <h3 class="green">{{ count }}</h3>
    <h3 class="green">{{ getLen }}</h3>
    <h3 class="green">{{ getLen }}</h3>
    <h3 class="green">{{ getLen }}</h3>
    <h3 class="green">{{ now() }}</h3>
    <button @click="clickHandler">修改</button>

    <p v-for="( item, key, index) in obj">这是内容: {{ item }} {{ key }} {{ index }}</p>


    <h3>
      You’ve successfully created a project with
      <a href="https://vitejs.dev/" target="_blank" rel="noopener">Vite</a> +
      <a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>.
    </h3>
  </div>
</template>

<style scoped>
h1 {
  font-weight: 500;
  font-size: 2.6rem;
  position: relative;
  top: -10px;
}

h3 {
  font-size: 1.2rem;
}

.greetings h1,
.greetings h3 {
  text-align: center;
}

@media (min-width: 1024px) {
  .greetings h1,
  .greetings h3 {
    text-align: left;
  }
}
</style>
